﻿using System;
using System.Web;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Collections.ObjectModel;


namespace EntiyInstanceSiteLib
{
    public partial class WebPartOrderForm : Form
    {
        public string[] leftZone, rightZone;

        public WebPartOrderForm()
        {
            InitializeComponent();
            }

        public WebPartOrderForm(string [] LeftZone, string[] RightZone)
        {
            InitializeComponent();
            LeftZoneListBox.Items.AddRange(LeftZone);
            rightZoneListBox.Items.AddRange(RightZone);
        }

        private void WebPartOrderForm_Load(object sender, EventArgs e)
        {
            LeftZoneListBox.SelectedIndex = 0;
            rightZoneListBox.SelectedIndex = 0;

        }
        /* when ISV want to move the webpart form Left zone to Right zone */
        private void addtoRightZoneButton_Click(object sender, EventArgs e)
        {
            string item;
            item = LeftZoneListBox.SelectedItem.ToString();
            LeftZoneListBox.Items.Remove(item);
            rightZoneListBox.Items.Add(item);
            addtoLeftZoneButton.Enabled = true;

            if (LeftZoneListBox.Items.Count > 0)
                LeftZoneListBox.SelectedIndex = 0;
            else
                addtoRightZoneButton.Enabled = false;

            if (rightZoneListBox.SelectedIndex == -1 && rightZoneListBox.Items.Count > 0)
                rightZoneListBox.SelectedIndex = 0;
        }

        /* when ISV want to move the webpart form Right zone to Left zone */
        private void addtoLeftZoneButton_Click(object sender, EventArgs e)
        {
            string item;
            item = rightZoneListBox.SelectedItem.ToString();
            rightZoneListBox.Items.Remove(item);
            LeftZoneListBox.Items.Add(item);
            
            addtoRightZoneButton.Enabled = true;
            if (rightZoneListBox.Items.Count > 0)
                rightZoneListBox.SelectedIndex = 0;
            else
                addtoLeftZoneButton.Enabled = false;

            if (LeftZoneListBox.SelectedIndex == -1 && LeftZoneListBox.Items.Count > 0)
                LeftZoneListBox.SelectedIndex = 0;
        }

        /* when ISV want to move the webpart to UP in Left zone */
        private void moveUpInLeftZone_Click(object sender, EventArgs e)
        {
            object item;
            
            int pos = LeftZoneListBox.SelectedIndex;
            if (pos <= 0) return;
            item = LeftZoneListBox.Items[pos];
            LeftZoneListBox.Items[pos] = LeftZoneListBox.Items[pos - 1];
            LeftZoneListBox.Items[pos-1] = item;
            LeftZoneListBox.SelectedIndex = pos - 1;
        }

        /* when ISV want to move the webpart to UP in Right zone */
        private void moveUpInRightZone_Click(object sender, EventArgs e)
        {
            object item;

            int pos = rightZoneListBox.SelectedIndex;
            if (pos <= 0) return;
            item = rightZoneListBox.Items[pos];
            rightZoneListBox.Items[pos] = rightZoneListBox.Items[pos - 1];
            rightZoneListBox.Items[pos-1] = item;
            rightZoneListBox.SelectedIndex = pos - 1;
        }

        /* when ISV Click on finish button */
        private void finishButton1_Click(object sender, EventArgs e)
        {
            leftZone = new string[LeftZoneListBox.Items.Count];
            rightZone = new string[rightZoneListBox.Items.Count];
            for (int i = 0; i < LeftZoneListBox.Items.Count; i++)
                leftZone[i] = LeftZoneListBox.Items[i].ToString();

            for (int i = 0; i < rightZoneListBox.Items.Count; i++)
                rightZone[i] = rightZoneListBox.Items[i].ToString();
            this.Close();

        }
        
        


 }
}
